Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: Reuse not_current_context in resumed() handler #1687

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

MarijnS95
Copy link
Member

@MarijnS95 MarijnS95 commented Jul 2, 2024

When testing the glutin example on Android, after suspending and resuming the app no triangle appears. As it turns out the winit 0.30 bump in #1678 never reuses the not_current_context that was set apart in suspended(), but creates a new one, without re-running initialization code such as creating the Renderer.

Partially restore original code before the winit 0.30 bump, which never created a context in resumed() because it was already available before the loop started (and moved back in place in suspended()). Note also that more initialization code that now (unnecessarily) lives in resumed() used to be outside of the loop.

  • Tested on all platforms changed
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

@MarijnS95
Copy link
Member Author

MarijnS95 commented Jul 2, 2024

CC @marc2332 @ErichDonGubler, note also that things from outside the loop were moved into fn resume() even though they probably shouldn't have been there to begin with?

EDIT: That's probably because WGL requires a window to be spawned before building a Display, which requires ActiveEventLoop which is only available in calls like fn resume()? Even though on Android that's not the case and most of this code could have ran before event_loop.run_app() 🙃

@ErichDonGubler
Copy link
Contributor

Ah, this was my bad, I think. I must have mistakenly interpreted the old code to re-init every time, but if the purpose of the not-current context is to be reused, then…😅 that's obviously incorrect.

glutin_examples/src/lib.rs Outdated Show resolved Hide resolved
@MarijnS95
Copy link
Member Author

@ErichDonGubler yes, it looks like everyone missed this in review. Probably clobbered by the fact that, on Windows/WGL, a window needs to be created before "making a connection to the compositor" (which is creating the display), which requires ActiveEventLoop since winit 0.30. In turn a lot of that setup code moved from outside the loop, into the loop (specifically into the resumed() call) to be able to do this.


There's a whole side-issue on winit where we're discussing and figuring out that resumed() has a lot more (platform-specific) semantics to it and isn't the right place to create windows either (unless the actual current usage is split out into a differently-named callback).

When testing the `glutin` example on Android, after suspending and
resuming the app no triangle appears.  As it turns out the `winit 0.30`
bump in rust-windowing#1678 never reuses the `not_current_context` that was set apart
in `suspend()`, but creates a new one, without re-running initialization
code such as creating the `Renderer`.

Partially restore original code before the `winit 0.30` bump, which
never created a context in `resume()` because it was already available
before the loop started (and moved back in place in `suspend()`). Note
also that more initialization code that now (unnecessarily) lives in
`resume()` used to be outside of the loop.
@kchibisov kchibisov merged commit 58afc41 into rust-windowing:master Jul 3, 2024
43 checks passed
@MarijnS95 MarijnS95 deleted the examples-android branch July 3, 2024 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants